package com.twu.biblioteca;


public class ReserveBookState implements State {

    private static ReserveBookState reserveBookStateInstance;
    Library books = Library.getLibraryInstance();

    private ReserveBookState() {

    }

    public static synchronized ReserveBookState getReserveBookStateInstance() {
        if (reserveBookStateInstance == null) {
            reserveBookStateInstance = new ReserveBookState();
        }

        return reserveBookStateInstance;

    }

    @Override
    public State change(String userInput) {
        changeAvailability(userInput);
        return DisplayBooksState.getDisplayBooksStateInstance();
    }

    @Override
    public String displayMenuOptions() {
        return null;
    }

    @Override
    public String displayWelcomeMessage() {
        return "Enter the number for the book you want to reserve:";
    }

    public String changeAvailability(String userInput) {
        int userInputInteger = Integer.parseInt(userInput);

        Book aBook = books.getBooks().get(userInputInteger);

        if (aBook.getAvailability()){
            aBook.setAvailability(false);
            return "Available";
        }

        aBook.setAvailability(true);
        return "Unavailable";

    }
}

/*
        int userInputInteger = Integer.parseInt(userInput);

        books.getBooks().get(userInputInteger).changeAvailability();

 */
